<?php
namespace Admin\Controller;

class OrderController extends AdminController
{
	public function order()
    {
        $nickname      = I('nickname');
        $map['status'] = array('egt', 0);
        if (is_numeric($nickname)) {
            $map['uid|gid'] = array(intval($nickname), array('like', '%' . $nickname . '%'), '_multi' => true);
        } else {
            $map['name'] = array('like', '%' . (string) $nickname . '%');
        }
        $list          = $this->lists('order', $map);
        $this->assign('_list', $list);
        $this->meta_title = '订单管理';
        $this->display();
    }

	public function update(){
		$id = I('get.id');
		$res = D('order')->where(array('id'=>$id))->setField('active','1');
		if($res){
			$this->success('成功修改为已发货状态');
		}else{
			$this->error(D('order')->getError());
		}
	}

	public function delete(){
		$id = I('get.id');
		$res = D('order')->where(array('id'=>$id))->delete();
		if($res){
			$this->success('删除订单删除成功！');
		}else{
			$this->error(D('order')->getError());
		}
	}

	public function changeStatus($method=null){
        $id = array_unique((array)I('id',0));
        if( in_array(C('USER_ADMINISTRATOR'), $id)){
            $this->error("不允许对超级管理员执行该操作!");
        }
        $id = is_array($id) ? implode(',',$id) : $id;
        if ( empty($id) ) {
            $this->error('请选择要操作的数据!');
        }
        $map['uid'] =   array('in',$id);
        switch ( strtolower($method) ){
            case 'forbiduser':
                $this->forbid('order', $map );
                break;
            case 'resumeuser':
                $this->resume('order', $map );
                break;
            case 'deleteuser':
                $this->delete('order', $map );
                break;
            default:
                $this->error('参数非法');
        }
    }
}